package com.idp.app.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.idp.app.dto.AppFeedbackDto;
import com.idp.app.dto.AppFeedbackSearchDto;
import com.idp.app.service.AppFeedbackService;
import com.idp.common.base.BaseController;
import com.idp.common.model.PageModel;
import com.idp.common.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 意见与反馈Controller
 * @author King
 */
@Api(tags="意见与反馈")
@RestController
@RequestMapping("/appFeedback/")
public class AppFeedbackController extends BaseController {

	@Autowired
	private AppFeedbackService appFeedbackService;

	/**
	 * 分页查询
	 * @param appFeedbackSearchDto
	 * @return
	 */
	@ApiOperation(value="分页查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "页数", paramType = "query", required = true, defaultValue = "1"),
			@ApiImplicitParam(name = "rows", value = "每页行数", paramType = "query", required = true, defaultValue = "10")
	})
	@PostMapping("findByPage")
	public ResultModel<PageModel<AppFeedbackDto>> findByPage(@RequestBody AppFeedbackSearchDto appFeedbackSearchDto) {
		return ResultModel.success(appFeedbackService.findByPage(appFeedbackSearchDto));
	}

	/**
	 * 通过主键查询
	 * @param appFeedbackDto
	 * @return
	 */
	@ApiOperation(value="通过主键查询")
	@ApiOperationSupport(includeParameters = {"appFeedbackDto.id"})
	@PostMapping("getById")
	public ResultModel<AppFeedbackDto> getById(@RequestBody AppFeedbackDto appFeedbackDto) {
		return ResultModel.success(appFeedbackService.getById(appFeedbackDto.getId()));
	}

	/**
	 * 新增
	 * @param appFeedbackDto
	 * @return
	 */
	@ApiOperation(value="新增")
	@ApiOperationSupport(includeParameters = {"appFeedbackDto.content", "appFeedbackDto.images"})
	@PostMapping("add")
	public ResultModel add(@RequestBody AppFeedbackDto appFeedbackDto) {
		appFeedbackService.add(appFeedbackDto);
		return ResultModel.success("新增成功", null);
	}

	/**
	 * 修改
	 * @param appFeedbackDto
	 * @return
	 */
	@ApiOperation(value="修改")
	@PostMapping("update")
	public ResultModel update(@RequestBody AppFeedbackDto appFeedbackDto) {
		appFeedbackService.update(appFeedbackDto);
		return ResultModel.success("修改成功", null);
	}

}
